package com.sxz.sbs.module.client.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sxz.sbs.R;
import com.sxz.sbs.module.client.bean.AddUserListBean;

import java.util.List;
import java.util.regex.Pattern;


/**
 * @author hp
 */
public class AddUserListAdapter extends BaseQuickAdapter<AddUserListBean.ListBean,BaseViewHolder>{
    public static final String REGEX_DATE_TIME = "^\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}$";
    public AddUserListAdapter(@Nullable List<AddUserListBean.ListBean> data) {
        super(R.layout.item_recommend,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AddUserListBean.ListBean item) {
        helper.setText(R.id.tv_username,"用户   "+item.getUserName());
        helper.setText(R.id.tv_salesman,"推荐人  "+item.getTxt_Name());
        helper.setText(R.id.tv_recommend_status,item.getState());
        helper.setText(R.id.tv_recommend_date,"注册时间："+ dateTransition(item.getCreateTime()));
    }
    public  String dateTransition (String targetDate) {
        if (!isMatch(REGEX_DATE_TIME,targetDate)) {
            return targetDate;
        }
        try {
            String[] arr = targetDate.split(" ");
            String result = arr[0];
            return  result;
        }catch (Exception e) {
            return "";
        }
    }
    public  boolean isMatch(final String regex, final CharSequence input) {
        return input != null && input.length() > 0 && Pattern.matches(regex, input);
    }
}
